#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/wait.h>
int main()
{
    printf("task begin.......\n");
    pid_t id=fork();
    if(id==0)//child
    {
        //putenv((char*)"putenv=112233445452132132");
        char *const argv[] = {
         (char*)"textexec",
          // (char*)"ls",
           (char*)"-a",
           (char*)"-l",
            NULL};
        char* const eee[]={
            (char*)"mypat=231232134",
            (char*)"uiiasd=00192",
            (char*)"fhsjdkfh=543679",
            NULL
        };
       // extern char**environ;
        printf("i am a child process, pid :%d,ppid:%d\n",getpid(),getppid());
        sleep(2);
        // execl("/usr/bin/ls","ls","-a","-l",NULL);
        // execlp("ls","ls","-a","-l",NULL);
        // execv("/usr/bin/ls",argv);
        // execvp("ls",argv);
        execve("./textexec",argv,eee);
        printf("child exit...\n");
        exit(111);//如果替换成功，就不会来到这里，直接退出就可以
    }
    //father
    pid_t rid=waitpid(id,NULL,0);
    if(rid)
    {
        printf("father wait sucess,child id:%d\n",rid);
    }
    return 0;
}
